package com.example.hasee.utils;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class NetUtils {
    private NetUtils(){

    }
    /**
     * 网络数据获取
     * @param url  网络资源
     * @return  输入数据流
     */
    public static InputStream getNetData(URL url){
        try {
            //通过url获取网络连接对象
            HttpURLConnection connection=(HttpURLConnection) url.openConnection();
            //通过连接对象建立网络连接
            connection.connect();
            //从连接对象中获取输入数据流
            return connection.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
